package com.eip.zd.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eip.zd.entity.Cust;
import com.eip.zd.entity.Standard;
import com.eip.zd.mapper.StandardMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StandardService {
    @Resource
    private StandardMapper standardMapper;
    @Resource
    private CustService custService;

    public List<Standard> getStandardList() {
        List<Cust> custList = custService.getCustList(null);
        List<Standard> standards = standardMapper.selectList(null);
        standards.stream().forEach(standard -> {
            custList.stream().forEach(cust -> {
                if (standard.getCustId().equals(cust.getCustId())) {
                    standard.setCustName(cust.getName());
                }
            });
        });
        return standards;
    }

    public void add(Standard standard) {
        standardMapper.insert(standard);
    }

    public void update(Standard standard) {
        standardMapper.updateById(standard);
    }

    public void remove(Long id) {
        standardMapper.deleteById(id);
    }

    public List<Standard> getCustStandard(String custId) {
        QueryWrapper<Standard> wrapper = new QueryWrapper<>();
        wrapper.eq("cust_id", custId);
        List<Standard> standardList = standardMapper.selectList(wrapper);
        return standardList;
    }
}
